package phoenixAAD.WifiFlashDrive;

import java.util.Scanner;

public enum DataType 
{
	/**
	 * ASCII format<br>
	 * The file need contain no vertical format information.<br>
	 * If it is passed to a printer process, this process may assume standard values for spacing and margins.<br>
     * Normally, this format will be used with files destined for processing or just storage.
	 */
	ASCII_NON_PRINT,
	/**
	 * ASCII format<br>
	 * The file contains ASCII/EBCDIC vertical format controls (i.e., CR, LF, NL, VT, FF) which the printer process will interpret appropriately.<br>
	 * CRLF, in exactly this sequence, also denotes end-of-line.
	 */
	@Deprecated
	ASCII_TELNET_FORMAT_CONTROL,
	/**
	 * Not in scope, not implemented
	 */
	@Deprecated
	ASCII_CARRIAGE_CONTROL,
	@Deprecated
	EBCDIC,
	IMAGE,
	@Deprecated
	LOCAL,
	/**
	 * For use in SendData
	 */
	LIST;
	
	/**
	 * Converts the character into the corresponding enum
	 * @throws NotImplementedException the specified data type is not implemented
	 * @throws SyntaxException bad argument was passed
	 */
	public static DataType getType(String arguments) throws NotImplementedException, SyntaxException
	{
		Scanner scan = new Scanner(arguments);
		if(!scan.hasNext())
			throw new SyntaxException(Response.BAD_ARGUMENT);
		char type = Character.toUpperCase(scan.next().charAt(0));
		switch(type)
		{
		case 'A':
		{
			if(scan.hasNext()) // if specifies ascii type
			{
				if(Character.toUpperCase(scan.next().charAt(0)) == 'N')
					return ASCII_NON_PRINT;
				else
					throw new NotImplementedException(Response.ARGUMENT_NOT_IMPLEMENTED);
			}
			else // return default
				return ASCII_NON_PRINT;
		}
		case 'I':
			return IMAGE;
		case 'E':
			throw new NotImplementedException(Response.ARGUMENT_NOT_IMPLEMENTED);
		case 'L':
		{
			if(scan.hasNext()) // if specifies a specific local type
			{
				if(Character.toUpperCase(scan.next().charAt(0)) == '8')
					return IMAGE; // RFC 1123 4.1.2.1 requirement, Local 8bit/byte is same as IMAGE
			}
			throw new NotImplementedException(Response.ARGUMENT_NOT_IMPLEMENTED);
		}
		default:
			throw new SyntaxException(Response.BAD_ARGUMENT);
		}
	}
}
